import $axios from "axios";
import store from '@/store/index'
import { Toast } from "vant";
const service = $axios.create({
  // 配置基本的路径
  baseURL: process.env.VUE_APP_URL,
  timeout: 5000
});
service.interceptors.request.use(
    (config) => {  
      Toast.loading("加载中")
      let token=store.state.token
      config.headers["user-token"] = token;
      return config;
    },
    (error) => {
      Promise.reject(error);
    }
  );
  service.interceptors.response.use(
    (response) => {
      // Toast.clear();
      const res = response.data;
      if (res.code == 666) {
      
        return res;
      } else {
        // 成功连接到后台, 但是没有返回正确的数据
        // alert(res.msg); 
      }
    },
    (error) => { 
      alert("网络异常,请稍后再试");
    }
  );
  

  export default service;
